#!/usr/bin/python
# -*- coding: utf8 -*-

#######################################################
## 数据通道类的实现
# 1、
# 2、
#######################################################

from queue import Queue
import threading
import time

class DataTunelSet:
    '数据通道集合类'

    def __init__(self):
        self.__tunnel_key_list = []
        self.__tunnel_tx_queue = []
        self.__tunnel_rx_queue = []

    def add(self):
        '添加通道'
        # 查询数据库表，获取数据通道属性
        queue = Queue()
        self.__tunnel_rx_queue.append(queue)
        queue = Queue()
        self.__tunnel_tx_queue.append(queue)

        tunnel
        self.__tunnel_key_list.append(tunnel)
        AliyunTunnel()

        tunnel = UartTunnel()
        self.__tunnel_key_list.append(tunnel)

    def remove(self, tunnel):
        '移除通道'
        pass

    def find(self, tunnel):
        '查询通道'
        pass

class DataTunnel(threading.Thread):
    '数据通道类'
    __tunnel_type = None
    __tunnel_direction = None
    __tunnel_name = None
    __tunnel_key = None

    def __init__(self, tx_queue, rx_queue):
        threading.Thread.__init__(self)
        self.tx_buf = tx_queue
        self.rx_buf = rx_queue

    def connect(self):
        '建立连接'
        pass

    def disconnect(self):
        '断开连接'
        pass

    def send(self):
        '发送数据'
        var = self.tx_buf.get()
        print("send %s" % var)

    def recv(self):
        '接收数据'
        print("recv data")
        self.rx_buf.put("recv")

class AliyunTunnel(DataTunnel):
    def __init__(self):
        DataTunnel.__init__(self)

    def run(self):
        while(self.tx_buf not None)
        self.send()
        time.sleep(1)
        self.recv()

class UartTunnel(DataTunnel):
    def __init__(self):
        DataTunnel.__init__(self)

    def run(self):
        self.recv()
        time.sleep(2)
        while(self.tx_buf not None)
        self.send()


if __name__ == '__main__':
    print("--- main thread ---")
    tx = Queue()
    rx = Queue()
